{extend name="adminblue/base" /}
{block name="resources"/}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/product.css">
<style type="text/css">
.num{width:40px;text-align:center;}
</style>
{/block}
{block name="main"}
<div class="options-btn">
	<button class="btn-common-delete btn-small" onclick="batchDelete()">批量删除</button>
	<button class="btn-common btn-small" onclick="location.href='{:__URL('ADMIN_MAIN/config/addlink')}';">添加友情链接</button>
</div>
<table class="table-class">
	<colgroup>
		<col style="width: 1%">
		<col style="width: 8%;">
		<col style="width: 10%;">
		<col style="width: 15%;">
		<col style="width: 20%;">
		<col style="width: 12%;">
		<col style="width: 10%;">
		<col style="width: 20%;">
		<col style="width:auto">
	</colgroup>
	<thead>
		<tr align="center">
			<th><input type="checkbox" onClick="CheckAll()"></th>
			<th>排序</th>
			<th>链接名称</th>
			<th>链接地址</th>
			<th>是否打开新窗口</th>
			<th>是否显示</th>
			<th>图片</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody id="linkList"></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
//全选
function CheckAll(){
	if($("#linkList input[type = 'checkbox']").attr("checked")){
		$("#linkList input[type = 'checkbox']").attr("checked",false);
	}else{
		$("#linkList input[type = 'checkbox']").attr("checked",true);
	}
}

//分页数据
function LoadingInfo(page_index) {
	var search_text = $("#search_text").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/linklist')}",
		data : {
			"page_index" : page_index, "page_size" : $("#showNumber").val()
		},
		success : function(data) {
			var html = '';
			if (data["data"].length > 0) {
				for (var i = 0; i < data["data"].length; i++) {
					html += '<tr align="center">';
					html += '<td><input name="sub" type="checkbox" value="'+ data['data'][i]['link_id']+'" ></td>';
					//html += '<td><input type="text" min="0" value="'+ data["data"][i]["link_sort"]+'"  nav_id="'+ data['data'][i]['link_id']+'" class="num" ></td>';
					html += '<td><span>'+ data["data"][i]["link_sort"]+'</span></td>';
					html += '<td title="'+data["data"][i]["link_title"]+'">' + data["data"][i]["link_title"]+ '</td>';
					html += '<td>' + data["data"][i]["link_url"]+ '</td>';
					if(data["data"][i]["is_blank"] == 1){
						html += '<td class="center"><a href="javascript:;" class="active" data-toggle="class"><i class="fa fa-check text-success text-active"></i></a></td>';
					}else{
						html += '<td class="center"><a href="javascript:;" class data-toggle="class"><i class="fa fa-times text-danger text"></i></a></td>';
					}
					if(data["data"][i]["is_show"] == 1){
						html += '<td class="center"><a href="javascript:;" class="active" data-toggle="class"><i class="fa fa-check text-success text-active"></i></a></td>';
					}else{
						html += '<td class="center"><a href="javascript:;" class data-toggle="class"><i class="fa fa-times text-danger text"></i></a></td>';
					}
					if(data["data"][i]["link_pic"] != ''){
						html += '<td><image src=' + __IMG(data["data"][i]["link_pic"])+ ' style="width:100px;"></td>';
					}else{
						html += '<td></td>';
					}
					html += '<td><a href="'+__URL('ADMIN_MAIN/config/updatelink?link_id='+ data['data'][i]['link_id'])+'">修改</a><a style="cursor: pointer;" onclick="deleteLink('+data['data'][i]['link_id']+')">删除</a></td> ';
					html += '</tr>';
				}
			} else {
				html += '<tr align="center"><td colspan="8">暂无友情链接</td></tr>';
			}
			$(".table-class tbody").html(html);
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function batchDelete() {
	var link_id= new Array();
	$(".table-class tbody input[type='checkbox']:checked").each(function() {
		if (!isNaN($(this).val())) {
			link_id.push($(this).val());
		}
	});
	if(link_id.length ==0){
		$( "#dialog" ).dialog({
			buttons: {
				"确定,#e57373": function() {
					$(this).dialog('close');
				}
			},
			contentText:"请选择需要操作的记录",
			title:"消息提醒",
		});
		return false;
	}
	deleteLink(link_id);
}

function deleteLink(link_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$(this).dialog('close');
					$.ajax({
					type:"post",
					url:"{:__URL('ADMIN_MAIN/config/dellink')}",
					data:{ 'link_id':link_id.toString() },
					success:function (data) {
						if(data['code'] > 0){
							LoadingInfo(getCurrentIndex(link_id,'.table-class tbody'));
							showMessage('success', data["message"]);
						}else{
							showMessage('error', data["message"]);
						}
					}
				});
			},
			"取消,#e57373": function() {
				$(this).dialog('close');
			}
		},
		contentText:"确定删除？",
	});
}
</script>
{/block}